package com.dd.cloud.user.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.cloud.common.constants.IntegralConstants;
import com.dd.cloud.common.vo.PageReq;
import com.dd.cloud.common.vo.PageVo;
import com.dd.cloud.user.entity.consult.PresImMsgRecord;
import com.dd.cloud.user.entity.consult.WebSocketImMsg;
import com.dd.cloud.user.entity.doctor.*;
import com.dd.cloud.user.entity.resource.AdvertInfo;
import com.dd.cloud.user.entity.resource.SpreadInfo;
import com.dd.cloud.user.req.consult.WebSocketPrivateGroupAdminPageReq;
import com.dd.cloud.user.req.consult.WebSocketReq;
import com.dd.cloud.user.req.doctor.*;
import com.dd.cloud.user.req.pres.PresImMsgRecordReq;
import com.dd.cloud.user.req.resource.AdvertInfoReq;
import com.dd.cloud.user.res.admin.StatisticalUserNumRes;
import com.dd.cloud.user.res.consult.WebSocketPrivateGroupAdminPageRes;
import com.dd.cloud.user.res.doctor.*;
import com.dd.cloud.user.res.product.ProductGiveRecordRes;
import com.dd.cloud.user.service.consule.IWebSocketImMsgService;
import com.dd.cloud.user.service.consule.IWebSocketPrivateGroupService;
import com.dd.cloud.user.service.doctor.*;
import com.dd.cloud.user.service.pres.IPresImMsgRecordService;
import com.dd.cloud.user.service.product.IProductGiveRecordService;
import com.dd.cloud.user.service.resource.IAdvertInfoService;
import com.dd.cloud.user.service.resource.ISpreadInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 医生账号信息表  前端控制器
 * </p>
 *
 * @author czg
 * @since 2022-04-27
 */
@RestController
@RequestMapping("/doctor")
@Validated
@Slf4j
public class DoctorController {
    @Autowired
    private IDoctorSignService doctorSignService;
    @Autowired
    private IDoctorUserService doctorUserService;
    @Autowired
    private IDoctorDetailService doctorDetailService;
    @Autowired
    private IPatientMedCardService patientMedCardService;
    @Autowired
    private IPatientMedCardStudyService patientMedCardStudyService;
    @Autowired
    private IPatientDeliveryAddrService patientDeliveryAddrService;
    @Autowired
    private IDoctorOrderIncomeDetailService doctorOrderIncomeDetailService;
    @Autowired
    private IDoctorWithdrawRecordService doctorWithdrawRecordService;
    @Autowired
    private IDoctorDetailApplyService doctorDetailApplyService;
    @Autowired
    private IDoctorDetailReviewService doctorDetailReviewService;
    @Autowired
    private IDoctorBankService doctorBankService;
    @Autowired
    private IBindReviewPresDoctorService bindReviewPresDoctorService;
    @Autowired
    private IDoctorSettingServiceService doctorSettingServiceService;

    @Autowired
    private IDoctorIntegralService doctorIntegralService;


    @Autowired
    private IProductGiveRecordService productGiveRecordService;

    @Autowired
    private IDoctorTaskListService doctorTaskListService;

    @Autowired
    private IDoctorStudyRecordService doctorStudyRecordService;

    @Autowired
    private IAdvertInfoService iAdvertInfoService;

    @Autowired
    private ISpreadInfoService spreadInfoService;

    @Autowired
    private IWebSocketImMsgService webSocketImMsgService;

    @Autowired
    private IWebSocketPrivateGroupService webSocketPrivateGroupService;

    @Autowired
    private IPresImMsgRecordService presImMsgRecordService;

    /**
     * 医生通过手机验证码登录
     *
     * @param phone 手机
     * @param code  验证码
     * @return 医生账号信息
     */
    @PostMapping("/login/phone")
    public ResponseEntity<DoctorUser> doctorLoginByPhone(HttpServletRequest request, HttpServletResponse response, @RequestParam("phone") String phone, @RequestParam(value = "code", required = false) String code, String model, String platId, String appId, Integer type, String cid) {
        log.info("医生通过手机验证码登录:{},{},{},{},{},{}", phone, code, model, platId, appId, type);
        DoctorUser doctorUser = doctorUserService.doctorLoginByPhone(request, response, phone, code, model, platId, appId, type, cid);
        return ResponseEntity.ok(doctorUser);
    }


    /**
     * 扫码登录 存储二维码时间戳
     *
     * @param timestamp
     */
    @PostMapping("/scan/qr/timestamp")
    public ResponseEntity<Void> doctorLoginScanSaveTime(@NotBlank(message = "二维码唯一标识不能为空") String timestamp) {
        doctorUserService.loginScanSaveTime(timestamp);
        return ResponseEntity.ok().build();
    }

    /**
     * 扫码登录 查询是否登录
     *
     * @param timestamp
     */
    @GetMapping("/scan/qr/isLogin")
    public ResponseEntity<DoctorQrScanReq> doctorScanIsLogin(@RequestParam("timestamp") String timestamp) {
        DoctorQrScanReq req = doctorUserService.doctorScanIsLogin(timestamp);
        return ResponseEntity.ok(req);
    }


    /**
     * 扫码登录 点击授权及取消
     *
     * @param timestamp
     * @param status
     */
    @PostMapping("/scan/authorization/click")
    public ResponseEntity<Void> doctorScanQrClick(@NotNull(message = "状态不能为空") Integer status, @NotBlank(message = "时间戳不能为空") String timestamp) {
        doctorUserService.doctorScanQrClick(status, timestamp);
        return ResponseEntity.ok().build();
    }


    /**
     * 扫码登录
     *
     * @param doctorId
     * @param timestamp
     */
    @PostMapping("/scan/qr/login")
    public ResponseEntity<DoctorUser> doctorScanLogin(@NotNull(message = "医生id不能为空") Integer doctorId, @NotBlank(message = "时间搓") String timestamp, HttpServletRequest request, HttpServletResponse response) {
        DoctorUser doctorUser = doctorUserService.doctorScanLogin(doctorId, request, response, timestamp);
        return ResponseEntity.ok(doctorUser);
    }

    /**
     * 删除二维码唯一值
     */
    @PostMapping("/scan/qr/delete")
    public ResponseEntity<Void> deleteDoctorQr(@NotBlank(message = "时间戳不能为空") String timestamp) {
        doctorUserService.deleteDoctorQr(timestamp);
        return ResponseEntity.ok().build();
    }

    /**
     * 医生通过账号密码登录
     *
     * @param phone 手机
     * @param psw   密码
     * @return 医生账号信息
     */
    @PostMapping("/login/account")
    public ResponseEntity<DoctorUser> doctorLoginByAccount(HttpServletRequest request, HttpServletResponse response, @RequestParam("phone") String phone, @RequestParam(value = "psw", required = false) String psw, String model, String platId, String appId, Integer type, String cid) {
        log.info("医生通过账号密码登录:{},{},{},{},{},{}", phone, psw, model, platId, appId, type);
        DoctorUser doctorUser = doctorUserService.doctorLoginByAccount(request, response, phone, psw, model, platId, appId, type, cid);
        return ResponseEntity.ok(doctorUser);
    }

    /**
     * 医生忘记密码
     *
     * @param phone
     * @param code
     * @param pwd
     * @param pwds
     */
    @PostMapping("/forget/pwd")
    public ResponseEntity<Void> doctorForgetPwd(@NotBlank(message = "手机号不能为空") String phone, @NotBlank(message = "验证码不能为空") String code, @NotBlank(message = "密码不能为空") String pwd, @NotBlank(message = "确认密码不能为空") String pwds) {
        doctorUserService.doctorForgetPwd(phone, code, pwd, pwds);
        return ResponseEntity.ok().build();
    }


    /**
     * 添加医生用户
     *
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<Void> register(@Valid @RequestBody DoctorCreateReq req) {
        log.info(" 医生添加信息======{}", req);
        doctorUserService.addDoctorUser(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加医生用户
     *
     * @return
     */
    @PostMapping("/add/excel")
    public ResponseEntity<DoctorExcelRes> registerByExcel(@NotNull(message = "请上传文件") MultipartFile file) {
        log.info(" excel医生添加信息======{}", file);
        DoctorExcelRes doctorExcelRes = doctorUserService.addDoctorBatchByExcel(file);
        return ResponseEntity.ok(doctorExcelRes);
    }

    /**
     * 医生修改信息
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public ResponseEntity<Void> material(@Valid @RequestBody DoctorDetailUpdateReq req) {
        log.info(" 医生修改信息======{}", req);
        doctorDetailService.updateDoctorDetail(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改医生资料 自定义参数
     *
     * @param req
     */
    @PostMapping("/update/opt")
    public ResponseEntity<Void> updateDoctorDetailUpdateOpt(@Valid @RequestBody DoctorDetailUpdateOptReq req) {
        log.info(" 修改医生资料 自定义参数======{}", req);
        doctorDetailService.updateDoctorDetailUpdateOpt(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生详细信息
     *
     * @param id
     * @return
     */
    @GetMapping("/info")
    public ResponseEntity<DoctorDetailRes> queryDoctorDetail(@RequestParam(value = "id", required = false) Integer id) {
        log.info("查询医生id======{}", id);
        DoctorDetailRes res = doctorDetailService.queryDoctorDetail(id);
        return ResponseEntity.ok(res);
    }

    /**
     * 医生修改密码
     *
     * @param id 医生ID
     * @param op 原密码
     * @param np 新密码
     * @return 无
     */
    @PostMapping("/cp")
    public ResponseEntity<Void> changePassword(Integer id, String op, String np) {
        log.info("医生修改密码=" + id + ",op=" + op + ",np=" + np);
        doctorUserService.changePassword(id, op, np);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    /**
     * 医生找回密码
     *
     * @param mobileNumber 手机号
     * @param code         手机验证码
     * @param np           新密码
     * @param cp           确认新密码
     * @return 无
     */
    @PostMapping("/fp")
    public ResponseEntity<Void> findPassword(@RequestParam("mobileNumber") String mobileNumber, @RequestParam("code") String code, @RequestParam("np") String np, @RequestParam("cp") String cp, HttpServletRequest request) {
        log.info("找回密码 mobileNumber=" + mobileNumber + ",code=" + code + ",np=" + np + ",cp=" + cp);
        doctorUserService.findPassword(mobileNumber, code, np, cp, request);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    /**
     * 查询医生id以及名称 下拉列表专用
     *
     * @param keyword
     * @return
     */
    @GetMapping("/name/select")
    public ResponseEntity<List<DoctorUserSelectRes>> queryDoctorUserSelect(@RequestParam(value = "keyword", required = false) String keyword) {
        List<DoctorUserSelectRes> res = doctorDetailService.queryDoctorUserSelect(keyword);
        return ResponseEntity.ok(res);
    }

    /**
     * 设置密码
     *
     * @param password
     * @param passwords
     */
    @PostMapping("/set/pwd")
    public ResponseEntity<Void> setPassWord(@RequestParam("password") String password, @RequestParam("passwords") String passwords) {
        doctorUserService.setPassWord(password, passwords);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询患者账号列表,分页
     *
     * @return
     */
    @GetMapping("/med/page")
    public ResponseEntity<IPage<PatientMedCardPageRes>> patientUserPage(@Valid ParamsMedCardReq req) {
        IPage<PatientMedCardPageRes> page = patientMedCardService.selPatientMedCard(req);
        return ResponseEntity.ok(page);
    }

    /**
     * 分页查询患者病历卡信息
     *
     * @param req
     * @return
     */
    @GetMapping("/med/mob/page")
    public ResponseEntity<IPage<PatientMedCardMobPageRes>> selPatientMedCardMobPage(@Valid ParamsMedCardMobPageReq req) {
        IPage<PatientMedCardMobPageRes> res = patientMedCardService.selPatientMedCardMobPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询患者账号列表,分页
     *
     * @return
     */
    @GetMapping("/med/list")
    public ResponseEntity<List<PatientMedCardListRes>> medList(@Valid ParamsMedCardListReq req) {
        List<PatientMedCardListRes> page = patientMedCardService.selPatientMedCardList(req);
        return ResponseEntity.ok(page);
    }

    /**
     * 分页查询患者病历卡信息
     *
     * @param req
     * @return
     */
    @GetMapping("/med/page/study")
    public ResponseEntity<IPage<PatientMedCardPageRes>> selPatientMedCardStudy(ParamsMedCardReq req) {
        IPage<PatientMedCardPageRes> page = patientMedCardStudyService.selPatientMedCardStudy(req);
        return ResponseEntity.ok(page);
    }

    /**
     * 分页查询患者病历卡信息
     *
     * @param req
     * @return
     */
    @GetMapping("/med/mob/page/study")
    public ResponseEntity<IPage<PatientMedCardMobPageRes>> selPatientMedCardMobPageStudy(ParamsMedCardMobPageReq req) {
        IPage<PatientMedCardMobPageRes> res = patientMedCardStudyService.selPatientMedCardMobPageStudy(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询患者就诊过的机构
     *
     * @return
     */
    @GetMapping("/med/mechan/list")
    public ResponseEntity<List<MedMechanListRes>> medMechanList(@NotBlank(message = "就诊卡号不能为空") String medId) {
        List<MedMechanListRes> list = patientMedCardService.getMedMechanList(medId);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询医生邀请的患者名单
     *
     * @param req
     * @return
     */
    @GetMapping("/med/invite/page")
    public ResponseEntity<IPage<DoctorInvitePatientPageRes>> queryDoctorInvitePatientPageRes(@Valid PageReq req) {
        IPage<DoctorInvitePatientPageRes> res = patientMedCardService.queryDoctorInvitePatientPageRes(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询患者列表 运营后台 分页
     *
     * @param req
     * @return
     */
    @GetMapping("/med/admin/page")
    public ResponseEntity<IPage<PatientMedCardPageAdminRes>> queryPatientMedCardPageAdmin(@Valid PatientMedCardPageAdminReq req) {
        IPage<PatientMedCardPageAdminRes> res = patientMedCardService.queryPatientMedCardPageAdmin(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询患者列表 运营后台 导出excel
     *
     * @param req
     */
    @GetMapping("/med/admin/export")
    public ResponseEntity<Void> exportPatientMedCardPageAdmin(PatientMedCardPageAdminReq req, HttpServletResponse response) {
        patientMedCardService.exportPatientMedCardPageAdmin(req, response);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加患者病历卡信息
     *
     * @param req 病历卡信息
     */
    @PostMapping("/med/add")
    public ResponseEntity<PatientMedCard> addMedCard(@Valid PatientMedCardCreateReq req) {
        log.info("添加患者病历卡=====>{}", req);
        return ResponseEntity.ok(patientMedCardService.addPatientMedCard(req));
    }

    /**
     * 添加患者病历卡信息
     *
     * @param req
     */
    @PostMapping("/med/add/h5")
    public ResponseEntity<Void> addPatientMedCardH5(@Valid @RequestBody PatientMedCardH5CreateReq req) {
        log.info("添加患者病历卡=====>{}", req);
        patientMedCardService.addPatientMedCardH5(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改就诊卡
     *
     * @param req 修改后的就诊卡信息
     */
    @PostMapping("/med/update")
    public ResponseEntity<Void> updateMedCard(@Valid PatientMedCardUpdateReq req) {
        log.info("修改患者病历卡=====>{}", req);
        patientMedCardService.updateMedCard(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改患者病历卡状态
     */
    @PostMapping("/med/update/status")
    public ResponseEntity<Void> updateMedCardStatus(@NotNull(message = "就诊卡id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        log.info("修改患者病历卡状态=====>id:{},status:{}", id, status);
        patientMedCardService.updateMedCardStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加患者病历卡 学习模式
     *
     * @param req
     * @return
     */
    @PostMapping("/med/add/study")
    public ResponseEntity<Void> addPatientMedCardStudy(@Valid PatientMedCardCreateReq req) {
        log.info("添加患者病历卡 学习模式=====>{}", req);
        patientMedCardStudyService.addPatientMedCardStudy(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加患者病历卡信息
     *
     * @param req
     */
    @PostMapping("/med/add/h5/study")
    public ResponseEntity<Void> addPatientMedCardH5Study(@Valid @RequestBody PatientMedCardH5CreateReq req) {
        log.info("添加患者病历卡 学习模式=====>{}", req);
        patientMedCardStudyService.addPatientMedCardH5Study(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改患者病历卡 学习模式
     *
     * @param req
     * @returncd
     */
    @PostMapping("/med/update/study")
    public ResponseEntity<Void> updateMedCardStudy(@Valid PatientMedCardUpdateReq req) {
        log.info("修改患者病历卡 学习模式=====>{}", req);
        patientMedCardStudyService.updateMedCardStudy(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改患者病历卡状态 学习模式
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/med/update/status/study")
    public ResponseEntity<Void> updateMedCardStatusStudy(@NotNull(message = "就诊卡信息记录id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        log.info("修改患者病历卡状态 学习模式=====>id:{},status:{}", id, status);
        patientMedCardStudyService.updateMedCardStatusStudy(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询患者信息
     *
     * @param medId
     * @return
     */
    @GetMapping("/med/detail")
    public ResponseEntity<PatientMedCardDetailRes> queryPatientMedCardDetail(@NotBlank(message = "患者就诊卡号不能为空") String medId) {
        PatientMedCardDetailRes res = patientMedCardService.queryPatientMedCardDetail(medId);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询患者信息 h5
     *
     * @param medId
     * @return
     */
    @GetMapping("/med/details/h5")
    public ResponseEntity<PatientMedCardDetailRes> queryPatientMedCardDetailsH5(@NotBlank(message = "患者就诊卡号不能为空") String medId) {
        PatientMedCardDetailRes res = patientMedCardService.queryPatientMedCardDetail(medId);
        return ResponseEntity.ok(res);
    }

    /**
     * 检查患者信息是否存在 存在返回信息
     *
     * @param req
     * @return
     */
    @GetMapping("/med/detail/h5")
    public ResponseEntity<PatientMedCardDetailH5Res> queryPatientMedCardDetailH5(PatientMedCardDetailH5Req req) {
        PatientMedCardDetailH5Res res = patientMedCardService.queryPatientMedCardDetailH5(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询医生列表后台
     *
     * @param req
     * @return
     */
    @GetMapping("/list/sys")
    public ResponseEntity<IPage<DoctorSysListRes>> queryDoctorListSys(@Valid DoctorSysListReq req) {
        IPage<DoctorSysListRes> res = doctorUserService.queryDoctorListSys(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 导出医生列表后台
     *
     * @param req
     * @param response
     */
    @GetMapping("/list/export/sys")
    public ResponseEntity<Void> exportDoctorUserSystemExcel(@Valid DoctorSysListReq req, HttpServletResponse response) {
        doctorUserService.exportDoctorUserSystemExcel(req, response);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询注销医生列表
     */
    @GetMapping("/logoff/page")
    public ResponseEntity<IPage<DoctorSysListRes>> getLogoOffPage(@Valid DoctorSysListReq req) {
        IPage<DoctorSysListRes> res = doctorUserService.getLogoOffPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询医生邀请名单列表
     *
     * @param req
     * @return
     */
    @GetMapping("/invite/page")
    public ResponseEntity<IPage<DoctorInvitePageRes>> queryDoctorInvitePage(DoctorInvitePageReq req) {
        IPage<DoctorInvitePageRes> res = doctorUserService.queryDoctorInvitePage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 修改医生状态
     *
     * @param doctorId
     * @param status
     */
    @PostMapping("/update/status")
    public ResponseEntity<Void> updateDoctorUserStatusById(@NotNull(message = "医生id不能为空") Integer doctorId, @NotNull(message = "医生状态不能为空") Integer status) {
        doctorUserService.updateDoctorUserStatusById(doctorId, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 开启处方
     */
    @PostMapping("/pres/open")
    public ResponseEntity<Void> updatePresPower(@NotNull(message = "医生id不能为空") Integer doctorId, @NotNull(message = "状态不能为空") Integer status) {
        doctorUserService.updatePresPower(doctorId, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 医生开通处方审方业务
     *
     * @param open 开启状态 0关闭 1开启
     */
    @PostMapping("/pres/review/bo/open")
    public ResponseEntity<Void> openDoctorUserPresReviewBo(@NotNull(message = "开启状态不能为空") Integer open) {
        doctorUserService.openDoctorUserPresReviewBo(open);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生处方权权限业务数据
     *
     * @param docId
     * @return
     */
    @GetMapping("/pres/power/bo")
    public ResponseEntity<DoctorUserPresBoRes> queryDoctorUserPresPowerBoRes(Integer docId) {
        DoctorUserPresBoRes res = doctorUserService.queryDoctorUserPresPowerBoRes(docId);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询可签约审方医生列表
     *
     * @param req
     * @return
     */
    @GetMapping("/can/singing/doctor/page")
    public ResponseEntity<IPage<CanSingingDoctorListRes>> queryCanSingingDoctorList(@Valid CanSingingDoctorPageReq req) {
        IPage<CanSingingDoctorListRes> res = doctorUserService.queryCanSingingDoctorList(req);
        return ResponseEntity.ok(res);
    }


    /**
     * 手动调用处理医生认证失效
     */
    @PostMapping("/auth/lapse/hand")
    public ResponseEntity<Void> doctorAuthLapse() {
        doctorUserService.doctorAuthLapse();
        return ResponseEntity.ok().build();
    }

    /**
     * 手动调用处理医生认证失效消息通知
     */
    @PostMapping("/auth/lapse/news/notice/hand")
    public ResponseEntity<Void> doctorAuthLapseNewsNotice() {
        doctorUserService.doctorAuthLapseNewsNotice();
        return ResponseEntity.ok().build();
    }

    /**
     * 申请签约审核医生
     *
     * @param req
     */
    @PostMapping("/bind/review/doc/apply")
    public ResponseEntity<Void> applyBindReviewPresDoctor(@RequestBody @Valid BindReviewPresDoctorCreateReq req) {
        bindReviewPresDoctorService.applyBindReviewPresDoctor(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 无处方权医生 解约审核医生
     *
     * @param req
     */
    @PostMapping("/bind/review/doc/rescind")
    public ResponseEntity<Void> rescindBindReviewPresDoctor(@Valid BindReviewPresDoctorRescindReq req) {
        bindReviewPresDoctorService.rescindBindReviewPresDoctor(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 无处方权医生 查询处方审核医生列表
     *
     * @return
     */
    @GetMapping("/bind/review/doc/list")
    public ResponseEntity<List<BindReviewPresDoctorListRes>> queryBindReviewPresDoctorList() {
        List<BindReviewPresDoctorListRes> res = bindReviewPresDoctorService.queryBindReviewPresDoctorList();
        return ResponseEntity.ok(res);
    }

    /**
     * 无处方权医生 查询可正常审方医生数量 用于开方判断是否能继续开方
     *
     * @return
     */
    @GetMapping("/bind/review/doc/normal/count")
    public ResponseEntity<Integer> queryBindReviewPresDoctorNormalCount() {
        Integer res = bindReviewPresDoctorService.queryBindReviewPresDoctorNormalCount(null);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询审核处方单列表
     *
     * @param req
     * @return
     */
    @GetMapping("/bind/review/pres/page")
    public ResponseEntity<PageVo<BindReviewPresPageRes>> queryBindReviewPresPage(@Valid BindReviewPresPageReq req) {
        PageVo<BindReviewPresPageRes> res = bindReviewPresDoctorService.queryBindReviewPresPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询审核处方数量
     *
     * @param req
     * @return
     */
    @GetMapping("/bind/review/pres/extend")
    public ResponseEntity<BindReviewPresPageRes.BindReviewPresExtendRes> queryBindReviewPresExtend(BindReviewPresPageReq req) {
        BindReviewPresPageRes.BindReviewPresExtendRes res = bindReviewPresDoctorService.queryBindReviewPresExtend(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 有处方权医生 查询无处方权医生申请记录
     *
     * @param req
     * @return
     */
    @GetMapping("/bind/review/doc/apply/page")
    public ResponseEntity<PageVo<BindReviewPresDoctorApplyPageRes>> queryBindReviewPresDoctorApplyPage(@Valid BindReviewPresDoctorApplyPageReq req) {
        PageVo<BindReviewPresDoctorApplyPageRes> res = bindReviewPresDoctorService.queryBindReviewPresDoctorApplyPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 有处方权医生审核无处方权医生申请记录
     *
     * @param req
     */
    @PostMapping("/bind/review/doc/review")
    public ResponseEntity<Void> bindReviewPresDoctorReview(@Valid BindReviewPresDoctorReviewReq req) {
        bindReviewPresDoctorService.bindReviewPresDoctorReview(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 有处方权医生 查询无处方权医生待审核数量
     *
     * @return
     */
    @GetMapping("/bind/review/doc/no/review/count")
    public ResponseEntity<Integer> queryBindReviewPresDoctorApplyNoReviewCount() {
        Integer res = bindReviewPresDoctorService.queryBindReviewPresDoctorApplyNoReviewCount();
        return ResponseEntity.ok(res);
    }

    /**
     * 重置医生密码
     *
     * @param doctorId
     */
    @PostMapping("/reset/pwd")
    public ResponseEntity<Void> resetDoctorPwd(@RequestParam(value = "doctorId", required = false) Integer doctorId) {
        doctorUserService.resetDoctorPwd(doctorId);
        return ResponseEntity.ok().build();
    }

    /**
     * 确认手机号是否存在
     *
     * @param phone
     * @return
     */
    @GetMapping("/check/phone/user")
    public ResponseEntity<Boolean> checkPhoneUsed(@NotBlank(message = "手机号不能为空") String phone, @NotNull(message = "查询类型不能为空") Integer type) {
        Boolean lean = doctorUserService.checkPhoneUser(phone, type);
        return ResponseEntity.ok(lean);
    }

    /**
     * 查询openid通过code
     *
     * @param code
     * @return
     */
    @GetMapping("/wx/openid")
    public ResponseEntity<String> queryOpenidByCode(@NotBlank(message = "code不能为空") String code) {
        String res = doctorUserService.queryOpenidByCode(code);
        return ResponseEntity.ok(res);
    }

    /**
     * 注册医生账号
     *
     * @param req
     */
    @PostMapping("/registry")
    public ResponseEntity<Void> registryDoctorUser(HttpServletRequest request, HttpServletResponse response, @Valid @RequestBody DoctorRegistryReq req) {
        doctorUserService.registryDoctorUser(request, response, req);
        return ResponseEntity.ok().build();
    }

    /**
     * 初始化医生邀请码
     */
    @PostMapping("/invite/code/init")
    public ResponseEntity<Void> initDoctorUserInviteCode() {
        doctorUserService.initDoctorUserInviteCode();
        return ResponseEntity.ok().build();
    }

    /**
     * 查询患者收货地址列表
     *
     * @param medId
     * @return
     */
    @GetMapping("/med/addr/list")
    public ResponseEntity<List<PatientDeliveryAddr>> getPatientDeliveryAddrList(@NotBlank(message = "就诊卡id不能为空") String medId) {
        List<PatientDeliveryAddr> addrList = patientDeliveryAddrService.getPatientDeliveryAddrList(medId);
        return ResponseEntity.ok(addrList);
    }

    /**
     * 添加患者收货地址
     *
     * @param req
     * @return
     */
    @PostMapping("/med/addr/add")
    public ResponseEntity<Void> addPatientDeliveryAddr(@Valid @RequestBody PatientDeliveryAddrCreateReq req) {
        patientDeliveryAddrService.addPatientDeliveryAddr(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加患者收货地址 h5
     *
     * @param req
     */
    @PostMapping("/med/addr/add/h5")
    public ResponseEntity<Void> addPatientDeliveryAddrH5(@Valid @RequestBody PatientDeliveryAddrH5CreateReq req) {
        patientDeliveryAddrService.addPatientDeliveryAddrH5(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改患者收货地址
     *
     * @param req
     * @return
     */
    @PostMapping("/med/addr/update")
    public ResponseEntity<Void> updatePatientDeliveryAddr(@Valid @RequestBody PatientDeliveryAddrUpdateReq req) {
        patientDeliveryAddrService.updatePatientDeliveryAddr(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改患者默认收货地址
     *
     * @param id
     * @return
     */
    @PostMapping("/med/addr/update/type")
    public ResponseEntity<Void> updatePatientDeliveryAddrType(@NotNull(message = "收货地址id不能为空") Integer id) {
        patientDeliveryAddrService.updateTypeDeliveryAddr(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改患者收货地址状态
     *
     * @param id
     * @return
     */
    @PostMapping("/med/addr/update/status")
    public ResponseEntity<Void> updatePatientDeliveryAddrStatus(@NotNull(message = "收货地址id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        patientDeliveryAddrService.updateDeliveryAddrStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加临时地址数据
     *
     * @param body
     */
    @PostMapping("/med/addr/add/temp")
    public ResponseEntity<Void> addDeliveryAddrTemp(@RequestBody String body) {
        patientDeliveryAddrService.addDeliveryAddrTemp(body);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取添加临时地址数据
     *
     * @param docId
     * @return
     */
    @GetMapping("/med/addr/query/temp")
    public ResponseEntity<Map<String, Object>> getDeliveryAddrTemp(@NotNull(message = "医生id不能为空") Integer docId) {
        Map<String, Object> res = patientDeliveryAddrService.getDeliveryAddrTemp(docId);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询医生收入明细 年统计
     *
     * @param req
     * @return
     */
    @GetMapping("/income/year/detail")
    public ResponseEntity<PageVo<DoctorOrderIncomeDetailListRes>> queryDoctorOrderIncomeDetailList(@Valid DoctorOrderIncomeDetailListReq req) {
        PageVo<DoctorOrderIncomeDetailListRes> res = doctorOrderIncomeDetailService.queryDoctorOrderIncomeDetailList(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询医生收入明细 月明细
     *
     * @param req
     * @return
     */
    @GetMapping("/income/month/detail")
    public ResponseEntity<PageVo<DoctorOrderIncomeDetailMonthListRes>> queryDoctorOrderIncomeDetailMonthList(@Valid DoctorOrderIncomeDetailMonthListReq req) {
        PageVo<DoctorOrderIncomeDetailMonthListRes> res = doctorOrderIncomeDetailService.queryDoctorOrderIncomeDetailMonthList(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 重置医生收益记录
     *
     * @return
     */
    @PostMapping("/income/detail/page/system/reset")
    public ResponseEntity<PageVo<DoctorOrderIncomeDetailPageSystemRes>> resetDoctorOrderIncomeDetailPageSystem() {
        doctorOrderIncomeDetailService.setAllOrderToIncomeDetail();
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生收入记录 运营后台
     *
     * @param req
     * @return
     */
    @GetMapping("/income/detail/page/system")
    public ResponseEntity<PageVo<DoctorOrderIncomeDetailPageSystemRes>> queryDoctorOrderIncomeDetailPageSystem(@Valid DoctorOrderIncomeDetailPageSystemReq req) {
        PageVo<DoctorOrderIncomeDetailPageSystemRes> res = doctorOrderIncomeDetailService.queryDoctorOrderIncomeDetailPageSystem(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 导出医生收入记录 运营后台
     *
     * @param response
     * @param req
     */
    @GetMapping("/income/detail/page/system/excel")
    public ResponseEntity<Void> exportDoctorOrderIncomeDetailSystemExcel(HttpServletResponse response, DoctorOrderIncomeDetailPageSystemReq req) {
        doctorOrderIncomeDetailService.exportDoctorOrderIncomeDetailSystemExcel(response, req);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生提现收入信息
     *
     * @param docId
     * @return
     */
    @GetMapping("/income/detail")
    public ResponseEntity<DoctorWithdrawIncomeInfoRes> queryDoctorWithdrawIncomeInfo(Integer docId) {
        DoctorWithdrawIncomeInfoRes res = doctorOrderIncomeDetailService.queryDoctorWithdrawIncomeInfo(docId);
        return ResponseEntity.ok(res);
    }

    /**
     * 医生申请提现收入
     *
     * @param req
     */
    @PostMapping("/withdraw/income")
    public ResponseEntity<Void> doctorWithdrawIncome(@Valid DoctorWithdrawIncomeReq req) {
        doctorWithdrawRecordService.doctorWithdrawIncome(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 医生查询提现记录
     *
     * @param req
     * @return
     */
    @GetMapping("/withdraw/income/page")
    public ResponseEntity<IPage<DoctorWithdrawRecordPageRes>> queryDoctorWithdrawRecordPage(@Valid DoctorWithdrawRecordPageReq req) {
        IPage<DoctorWithdrawRecordPageRes> res = doctorWithdrawRecordService.queryDoctorWithdrawRecordPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询提现记录详情
     *
     * @param withdrawNo
     * @return
     */
    @GetMapping("/withdraw/income/detail")
    public ResponseEntity<DoctorWithdrawRecordDetailRes> queryDoctorWithdrawRecordDetail(@NotBlank(message = "提现编号不能为空") String withdrawNo) {
        DoctorWithdrawRecordDetailRes res = doctorWithdrawRecordService.queryDoctorWithdrawRecordDetail(withdrawNo);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询所有医生提现记录 运营后台
     *
     * @param req
     * @return
     */
    @GetMapping("/withdraw/income/page/system")
    public ResponseEntity<IPage<DoctorWithdrawRecordPageSystemRes>> queryDoctorWithdrawRecordPageSystem(@Valid DoctorWithdrawRecordPageSystemReq req) {
        IPage<DoctorWithdrawRecordPageSystemRes> res = doctorWithdrawRecordService.queryDoctorWithdrawRecordPageSystem(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询所有医生提现记录 运营后台 导出excel
     *
     * @param response
     * @param req
     * @return
     */
    @GetMapping("/withdraw/income/page/system/export")
    public ResponseEntity<Void> exportDoctorWithdrawRecordPageSystemExcel(HttpServletResponse response, DoctorWithdrawRecordPageSystemReq req) {
        doctorWithdrawRecordService.exportDoctorWithdrawRecordPageSystemExcel(response, req);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询单个医生提现记录 运营后台 导出excel
     *
     * @param response
     * @param req
     * @return
     */
    @GetMapping("/withdraw/income/page/system/single/export")
    public ResponseEntity<Void> exportSingleDoctorWithdrawRecordPageSystemExcel(HttpServletResponse response, DoctorWithdrawRecordPageSystemReq req) {
        doctorWithdrawRecordService.exportSingleDoctorWithdrawRecordPageSystemExcel(response, req);
        return ResponseEntity.ok().build();
    }

    /**
     * 医生申请提现 后台打款
     *
     * @param req
     */
    @PostMapping("/withdraw/income/payment/system")
    public ResponseEntity<Void> doctorWithdrawPayment(@Valid @RequestBody DoctorWithdrawPaymentReq req) {
        doctorWithdrawRecordService.doctorWithdrawPayment(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 上传医生签名
     *
     * @param signBase
     */
    @PostMapping("/upload/sign/base64")
    public ResponseEntity<Void> uploadDoctorSign(@NotBlank(message = "医生签名base64不能为空") String signBase) {
        doctorSignService.uploadDoctorSign(signBase);
        return ResponseEntity.ok().build();
    }


    /**
     * 上传PC医生签名websocket
     *
     * @param signBase
     */
    @PostMapping("/h5/upload/sign/base64")
    public ResponseEntity<Void> uploadDoctorSignH5(@NotBlank(message = "医生签名base64不能为空") String signBase, @NotNull(message = "医生id不能为空") Integer doctorId) {
        log.info("上传医生签字 参数{}", doctorId);
        doctorSignService.uploadDoctorSignH5(signBase, doctorId);
        return ResponseEntity.ok().build();
    }


    /**
     * 保存PC医生签名到数据库
     *
     * @param signBase
     */
    @PostMapping("/h5/save/sign/base64")
    public ResponseEntity<Void> saveDoctorSignH5(@NotBlank(message = "医生签名base64不能为空") String signBase, @NotNull(message = "医生id不能为空") Integer doctorId) {
        log.info("上传医生签字 参数{}", doctorId);
        doctorSignService.saveDoctorSignH5(signBase, doctorId);
        return ResponseEntity.ok().build();
    }

    /**
     * 上传医生签名 url地址
     *
     * @param signUrl
     */
    @PostMapping("/upload/sign/url")
    public ResponseEntity<Void> uploadDoctorSignUrl(@NotBlank(message = "医生签名url不能为空") String signUrl) {
        doctorSignService.uploadDoctorSignUrl(signUrl);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生签名
     *
     * @return
     */
    @GetMapping("/sign/query")
    public ResponseEntity<DoctorSign> queryDoctorSign(@RequestParam(required = false) Integer docId) {
        DoctorSign res = doctorSignService.queryDoctorSign(docId);
        return ResponseEntity.ok(res);
    }

    /**
     * 医生(认证申请/修改资料/互联网执业备案)提交申请
     *
     * @param req
     */
    @PostMapping("/detail/apply")
    public ResponseEntity<Void> addDoctorDetailApplyAuth(@RequestBody DoctorDetailApplyAuthReq req) {
        doctorDetailApplyService.addDoctorDetailApplyAuth(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生最后一次(认证申请/修改资料/互联网执业备案)信息状态
     * 医生id不传默认当前登录医生id
     *
     * @param docId
     * @param type
     * @return
     */
    @GetMapping("/detail/apply/last/status")
    public ResponseEntity<Map<String, Integer>> getDoctorDetailApplyLastStatus(@RequestParam(value = "docId", required = false) Integer docId, @RequestParam(value = "type", required = false) Integer type) {
        Map<String, Integer> res = doctorDetailApplyService.getDoctorDetailApplyLastStatus(docId, type);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询医生最后一次(认证申请/修改资料/互联网执业备案)审核提示
     * 医生id不传默认当前登录医生id
     *
     * @param docId
     * @param type
     * @return
     */
    @GetMapping("/detail/apply/last/tip")
    public ResponseEntity<DoctorDetailApplyLastTipRes> getDoctorDetailApplyLastTip(@RequestParam(value = "docId", required = false) Integer docId, @RequestParam(value = "type", required = false) Integer type, HttpServletRequest request) {
        DoctorDetailApplyLastTipRes res = doctorDetailApplyService.getDoctorDetailApplyLastTip(docId, type, request);
        return ResponseEntity.ok(res);
    }


//    /**
//     * 查询医生最后一次(认证申请/修改资料/互联网执业备案)审核提示
//     * 医生id不传默认当前登录医生id
//     *
//     * @param docId
//     * @param type
//     * @return
//     */
//    @GetMapping("/pc/detail/apply/last/tip")
//    public ResponseEntity<DoctorDetailApplyLastTipRes> getPcDoctorDetailApplyLastTip(@RequestParam(value = "docId", required = false) Integer docId, @RequestParam(value = "type", required = false) Integer type) {
//        DoctorDetailApplyLastTipRes res = doctorDetailApplyService.getPcDoctorDetailApplyLastTip(docId, type);
//        return ResponseEntity.ok(res);
//    }

    /**
     * 查询医生最后一次(认证申请/修改资料/互联网执业备案)信息记录
     * 医生id不传默认当前登录医生id
     *
     * @param docId
     * @param type
     * @return
     */
    @GetMapping("/detail/apply/last")
    public ResponseEntity<DoctorDetailApplyDetailRes> getDoctorDetailApplyDetailLast(@RequestParam(value = "docId", required = false) Integer docId, @RequestParam(value = "type", required = false) Integer type) {
        DoctorDetailApplyDetailRes res = doctorDetailApplyService.getDoctorDetailApplyDetailLast(docId, type);
        return ResponseEntity.ok(res);
    }

    /**
     * 医生(认证申请/修改资料/互联网备案) 审核
     *
     * @param req
     */
    @PostMapping("/detail/apply/review")
    public ResponseEntity<Void> doctorDetailApplyReview(@Valid @RequestBody DoctorDetailApplyReviewReq req) {
        doctorDetailApplyService.doctorDetailApplyReview(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生认证/信息修改申请记录 分页
     *
     * @param req
     * @return
     */
    @GetMapping("/detail/apply/page")
    public ResponseEntity<IPage<DoctorDetailApplyPageRes>> queryDoctorDetailApplyPage(@Valid DoctorDetailApplyPageReq req) {
        IPage<DoctorDetailApplyPageRes> res = doctorDetailApplyService.queryDoctorDetailApplyPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询医生认证/信息修改审核记录 分页
     *
     * @param req
     * @return
     */
    @GetMapping("/detail/apply/review/page")
    public ResponseEntity<IPage<DoctorDetailApplyReviewPageRes>> queryDoctorDetailApplyReviewPage(@Valid DoctorDetailApplyReviewPageReq req) {
        IPage<DoctorDetailApplyReviewPageRes> res = doctorDetailApplyService.queryDoctorDetailApplyReviewPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询医生认证/信息修改申请记录详情
     *
     * @param applyId
     * @return
     */
    @GetMapping("/detail/apply/detail")
    public ResponseEntity<DoctorDetailApplyDetailRes> queryDoctorDetailApplyDetailRes(@NotNull(message = "申请记录id不能为空") Integer applyId) {
        DoctorDetailApplyDetailRes res = doctorDetailApplyService.queryDoctorDetailApplyDetailRes(applyId);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询申请记录审核信息
     *
     * @param applyId
     * @return
     */
    @GetMapping("/detail/apply/review/detail")
    public ResponseEntity<DoctorDetailReviewDetailRes> queryDoctorDetailReviewDetail(@NotNull(message = "申请记录id不能为空") Integer applyId) {
        DoctorDetailReviewDetailRes res = doctorDetailReviewService.queryDoctorDetailReviewDetail(applyId);
        return ResponseEntity.ok(res);
    }

    /**
     * 医生详情表获取机构名称 兼容数据处理  上线调用一次
     */
    @PostMapping("/mechanName")
    public ResponseEntity<Void> updateMechanName() {
        doctorUserService.updateMechanName();
        return ResponseEntity.ok().build();
    }

    /**
     * 修改医生账号类型
     *
     * @param doctorId
     * @param type
     */
    @PostMapping("/update/type")
    public ResponseEntity<Void> updateDoctorUserType(@NotNull(message = "医生id不能为空") Integer doctorId, @NotNull(message = "账号类型不能为空") Integer type) {
        doctorUserService.updateDoctorUserType(doctorId, type);
        return ResponseEntity.ok().build();
    }

    /**
     * 医生账号注销
     *
     * @param request
     * @param phone
     * @param code
     */
    @PostMapping("/user/logoff")
    public ResponseEntity<Void> doctorUserAccountLogoff(HttpServletRequest request, @NotBlank(message = "手机号不能为空") String phone, @NotBlank(message = "验证码不能为空") String code) {
        doctorUserService.doctorUserAccountLogoff(request, phone, code);
        return ResponseEntity.ok().build();
    }


    /**
     * 添加修改银行
     */
    @PostMapping("/addOrUpdate/bank")
    public ResponseEntity<Void> addOrUpdateDoctorBank(@Valid @RequestBody DoctorBankReq doctorBankReq) {
        doctorBankService.addOrUpdateDoctorBank(doctorBankReq);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询银行卡
     */
    @GetMapping("/get/bank")
    public ResponseEntity<DoctorBankRes> getDoctorBank() {
        DoctorBankRes res = doctorBankService.getDoctorBank();
        return ResponseEntity.ok(res);
    }

    /**
     * 根据银行卡号查询银行类型名称
     */
    @GetMapping("/code/bank/type")
    public ResponseEntity<String> getBankType(@RequestParam("cardNo") String cardNo) {
        String bankCode = doctorBankService.getBankType(cardNo);
        return ResponseEntity.ok(bankCode);
    }


    /**
     * 查询医生的服务设置
     */
    @GetMapping("/setting/service")
    public ResponseEntity<DoctorSettingService> getDoctorSettingService(@RequestParam("doctorId") Integer doctorId) {
        DoctorSettingService res = doctorSettingServiceService.getDoctorSettingService(doctorId);
        return ResponseEntity.ok(res);
    }

    /**
     * 添加修改医生服务设置
     */
    @PostMapping("/setting/service")
    public ResponseEntity<Void> addOrUpdateDoctorSettingService(@Valid @RequestBody DoctorSettingServiceFrom doctorSettingServiceFrom) {
        doctorSettingServiceService.addOrUpdateDoctorSettingService(doctorSettingServiceFrom);
        return ResponseEntity.ok().build();
    }

    /**
     * 互联网备案医生列表
     */
    @GetMapping("/internet/page")
    public ResponseEntity<IPage<InternetDoctorRes>> queryDoctorPage(@Valid InternetDoctorReq internetDoctorReq) {
        IPage<InternetDoctorRes> res = doctorDetailService.queryDoctorPage(internetDoctorReq);
        return ResponseEntity.ok(res);
    }

    /**
     * 推送监管
     */
    @PostMapping("/internet/push")
    public ResponseEntity<Void> pushInternetDoctor(@RequestParam("doctorIds") List<Integer> doctorIds) {
        doctorDetailService.pushInternetDoctor(doctorIds);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取医生小程序二维码
     */
    @GetMapping("/qrCode")
    public ResponseEntity<String> getDoctorQr(@RequestParam(name = "param") String param, @RequestParam(name = "page") String page, @RequestParam(name = "doctorId") Integer doctorId) {
        String qrCode = doctorDetailService.getDoctorQr(page, param, doctorId);
        return ResponseEntity.ok(qrCode);
    }

    /**
     * 获取患者公众号二维码
     *
     * @param docId 医生id 医生登录非必传
     * @param param 自定义二维码参数字符串
     * @return
     */
    @GetMapping("/patient/gzh/qrCode")
    public ResponseEntity<String> getPatientGZHWxQr(@RequestParam(required = false) Integer docId, @RequestParam(required = false) String param) {
        String res = doctorDetailService.getPatientGZHWxQr(docId, param);
        return ResponseEntity.ok(res);
    }

    /**
     * 互联网备案审核页面
     */
    @GetMapping("/internet/apply/page")
    public ResponseEntity<IPage<InternetDoctorApplyRes>> queryInternetDoctorPage(@Valid DoctorInternetApplyReq doctorInternetApplyReq) {
        IPage<InternetDoctorApplyRes> res = doctorDetailService.queryInternetDoctorPage(doctorInternetApplyReq);
        return ResponseEntity.ok(res);
    }


    /**
     * 查询我的积分
     */
    @GetMapping("/integral/list")
    public ResponseEntity<List<DoctorIntegraRes>> queryIntegralList(DoctorIntegralReq doctorIntegralReq) {
        List<DoctorIntegraRes> res = doctorIntegralService.queryIntegralList(doctorIntegralReq);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询可以获取的积分
     */
    @GetMapping("/integral/home/list")
    public ResponseEntity<List<DoctorIntegral>> queryIntegralHomeList() {
        List<DoctorIntegral> res = doctorIntegralService.queryIntegralHomeList();
        return ResponseEntity.ok(res);
    }

    /**
     * 领取积分
     */
    @PostMapping("/integral/status")
    public ResponseEntity<Void> updateStatus(@RequestParam(name = "id", required = true) Integer id) {
        doctorIntegralService.updateStatus(id, IntegralConstants.status.RECEIVED);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取阅读奖励 (书籍没有医生id)
     */
    @PostMapping("/integral/read/add")
    public ResponseEntity<Void> insertReadIntegral(@NotNull(message = "类型不能为空") Integer type,
                                                   @NotNull(message = "医生id不能为空") Integer doctorId,
                                                   Integer postId) {
        doctorIntegralService.insertReadIntegral(type, doctorId, postId);
        return ResponseEntity.ok().build();
    }

    /**
     * 统计剩余积分
     */
    @GetMapping("/integral/use/total")
    public ResponseEntity<Integer> queryIntegralUseTotal() {
        Integer total = doctorIntegralService.queryIntegralUseTotal();
        return ResponseEntity.ok(total);
    }

    /**
     * 修改更新app版本赠送未认证使用免费次数版本号
     *
     * @param freeAiVersion
     */
    @PostMapping("/user/freeAiVersion/update")
    public ResponseEntity<Void> updateFreeAiVersion(@NotBlank(message = "更新app版本赠送未认证使用免费次数版本号不能为空") String freeAiVersion) {
        doctorUserService.updateFreeAiVersion(freeAiVersion);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改功能引导,科室引导
     *
     * @param functionGuide
     * @param depGuide
     */
    @PostMapping("/user/functionGuide/depGuide/update")
    public ResponseEntity<Void> updateFunctionGuideOrDepGuide(String functionGuide, String depGuide) {
        doctorUserService.updateFunctionGuideOrDepGuide(functionGuide, depGuide);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询医生患者数量/订单数量
     */
    @GetMapping("/statistical/doctor/num")
    public ResponseEntity<StatisticalUserNumRes> getStatisticalUserNum() {
        StatisticalUserNumRes res = doctorUserService.getStatisticalUserNum();
        return ResponseEntity.ok(res);
    }


    /**
     * 各个时间维度医生收益统计
     */
    @GetMapping("/statistical/doctor/income/node")
    public ResponseEntity<List<DoctorStatisticalNodeRes>> getStatisticalDoctorIncomeNode(@Valid DoctorStatisticalNodeReq req) {
        List<DoctorStatisticalNodeRes> res = doctorUserService.getStatisticalDateNode(req);
        return ResponseEntity.ok(res);
    }


    /**
     * 各个时间维度医生开方统计
     */
    @GetMapping("/statistical/doctor/pres/node")
    public ResponseEntity<List<DoctorStatisticalNodeRes>> getStatisticalDoctorPresNumNode(@Valid DoctorStatisticalNodeReq req) {
        List<DoctorStatisticalNodeRes> res = doctorUserService.getStatisticalDoctorPresNumNode(req);
        return ResponseEntity.ok(res);
    }


    /**
     * 查询医生积分(分页)
     */
    @GetMapping("/integral/page")
    public ResponseEntity<PageVo<DoctorIntegral>> queryDoctorIntegralPage(@Valid DoctorIntegralPageReq req) {
        PageVo<DoctorIntegral> page = doctorUserService.queryDoctorIntegralPage(req);
        return ResponseEntity.ok(page);
    }


    /**
     * 获得积分,消耗积分,剩余积分
     */
    @GetMapping("/query/integral")
    public ResponseEntity<DoctorIntegralDataRes> queryDoctorIntegral() {
        DoctorIntegralDataRes res = doctorIntegralService.queryDoctorIntegral();
        return ResponseEntity.ok(res);
    }


    /**
     * 查询收益记录
     */
    @GetMapping("/query/income/page")
    public ResponseEntity<PageVo<DoctorOrderIncomePageRes>> queryDoctorIncomePage(@Valid DoctorOrderIncomePageReq req) {
        PageVo<DoctorOrderIncomePageRes> page = doctorOrderIncomeDetailService.queryDoctorIncomePage(req);
        return ResponseEntity.ok(page);
    }


    /**
     * 查询提现记录
     */
    @GetMapping("/query/withdraw/record/page")
    public ResponseEntity<PageVo<DoctorWithdrawRecordPageSystemRes>> queryWithdrawRecordPage(@Valid DoctorWithdrawPageReq req) {
        PageVo<DoctorWithdrawRecordPageSystemRes> page = doctorOrderIncomeDetailService.queryWithdrawRecordPage(req);
        return ResponseEntity.ok(page);
    }


    /**
     * socket连接上消息内容发送
     *
     * @param req
     */
    @PostMapping("/websocket/chat")
    public ResponseEntity<Void> sendWebsocketChat(@Valid @RequestBody DoctorWebSocketChatReq req) {
        log.info("聊天 参数{}", JSON.toJSON(req));
        doctorSignService.sendWebsocketChat(req);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/websocket/chat/test")
    public ResponseEntity<Void> testWebsocket(String content, String sid) throws IOException {
        doctorSignService.testWebsocket(content, sid);
        return ResponseEntity.ok().build();
    }

    /**
     * 社会账号赠送提醒
     */
    @GetMapping("/presenter/num/tip")
    public ResponseEntity<ProductGiveRecordRes> remindDoctorTip(@RequestParam("isReceive") Integer isReceive) {
        ProductGiveRecordRes res = productGiveRecordService.remindDoctorTip(isReceive);
        return ResponseEntity.ok(res);
    }


    /**
     * 该用户是否为会员
     */
    @GetMapping("/isMember")
    public ResponseEntity<Boolean> queryIsMember() {
        Boolean flag = productGiveRecordService.queryIsMember();
        return ResponseEntity.ok(flag);
    }


    /**
     * 修改领取状态
     */
    @PostMapping("/presenter/update/status")
    public ResponseEntity<Void> updatePresenterUpdateStatus(@NotNull(message = "赠送次数id不能为空") Integer productGiveId, @NotNull(message = "状态 2.已领取 3.已使用") Integer status) {
        productGiveRecordService.updatePresenterUpdateStatus(productGiveId, status);
        return ResponseEntity.ok().build();
    }


    /**
     * 兼容线上收益数据
     */
    @PostMapping("/income/test")
    public ResponseEntity<Void> testIncomeTest() {
        doctorWithdrawRecordService.testIncomeTest();
        return ResponseEntity.ok().build();
    }

    /**
     * 数据兼容
     */
    @PostMapping("/income/test01")
    public ResponseEntity<Void> testIncomeTest01() {
        doctorWithdrawRecordService.testIncomeTest01();
        return ResponseEntity.ok().build();
    }


    /**
     * 获取医生推荐任务
     */
    @GetMapping("/task/one/list")
    public ResponseEntity<List<DoctorTaskList>> queryDoctorOneTaskList() {
        List<DoctorTaskList> tasks = doctorTaskListService.queryDoctorOneTaskList();
        return ResponseEntity.ok(tasks);
    }


    /**
     * 获取周期任务
     */
    @GetMapping("/task/two/list")
    public ResponseEntity<List<DoctorTaskList>> queryDoctorTwoTaskList() {
        List<DoctorTaskList> tasks = doctorTaskListService.queryDoctorTwoTaskList();
        return ResponseEntity.ok(tasks);
    }

    /**
     * 医案/中草药/方剂任务
     */
    @PostMapping("/task/integral")
    public ResponseEntity<Void> addTaskIntegral(@NotNull(message = "类型不能为空") Integer type, @NotNull(message = "阅读时间不能为空") Integer time) {
        doctorTaskListService.addTaskIntegral(type, time);
        return ResponseEntity.ok().build();
    }


    /**
     * 保存免费诊疗聊天记录
     */
    @PostMapping("/add/pres/msg")
    public ResponseEntity<Void> addPresImMsgRecord(@Valid @RequestBody PresImMsgRecordReq presImMsgRecordReq) {
        presImMsgRecordService.addPresImMsgRecord(presImMsgRecordReq);
        return ResponseEntity.ok().build();
    }

    /**
     * 处方记录聊天
     */
    @GetMapping("/pres/im/list")
    public ResponseEntity<List<PresImMsgRecord>> queryWebSocketImList(@RequestParam("tencode") String tencode) {
        List<PresImMsgRecord> list = presImMsgRecordService.queryWebSocketImList(tencode);
        return ResponseEntity.ok(list);
    }


    /**
     * 专家记录聊天
     */
    @GetMapping("/webSocket/im/list")
    public ResponseEntity<List<WebSocketImMsg>> queryWebSocketImMsg(@RequestParam("privateGroupId") Integer privateGroupId) {
        List<WebSocketImMsg> list = webSocketImMsgService.queryWebSocketImMsg(privateGroupId);
        return ResponseEntity.ok(list);
    }

    /**
     * 运营后台查询聊天记录
     *
     * @param privateGroupId 私聊id
     * @param type           消息类型 1文字 2图片
     * @param keyword        关键字
     * @return
     */
    @GetMapping("/webSocket/im/list/system")
    public ResponseEntity<Object> queryWebSocketImMsgSystem(@RequestParam("privateGroupId") Integer privateGroupId, Integer type, String keyword) {
        Object res = webSocketImMsgService.queryWebSocketImMsgSystem(privateGroupId, type, keyword);
        return ResponseEntity.ok(res);
    }

    /**
     * 修改消息为已读
     */
    @PostMapping("/webSocket/im/stauts")
    public ResponseEntity<Void> updateWebSocketImStatus(@NotNull(message = "私聊id") Integer privateGroupId) {
        webSocketImMsgService.updateWebSocketImStatus(privateGroupId);
        return ResponseEntity.ok().build();
    }

    /**
     * 点击接受
     */
    @PostMapping("/webSocket/im/accept")
    public ResponseEntity<Void> acceptWebSocketIm(@NotNull(message = "私聊id不能为空") Integer privateGroupId) {
        webSocketImMsgService.acceptWebSocketIm(privateGroupId);
        return ResponseEntity.ok().build();
    }

    /**
     * 结束更新记录
     *
     * @param privateGroupId
     */
    @PostMapping("/webSocket/im/end")
    public ResponseEntity<Void> endWebSocketIm(@NotNull(message = "私聊id不能为空") Integer privateGroupId) {
        webSocketImMsgService.endWebSocketIm(privateGroupId);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询沟通记录列表 分页
     *
     * @param req
     * @return
     */
    @GetMapping("/webSocket/group/admin/page")
    public ResponseEntity<PageVo<WebSocketPrivateGroupAdminPageRes>> queryWebSocketPrivateGroupAdminPage(@Valid WebSocketPrivateGroupAdminPageReq req) {
        PageVo<WebSocketPrivateGroupAdminPageRes> res = webSocketPrivateGroupService.queryWebSocketPrivateGroupAdminPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 添加学习记录
     */
    @PostMapping("/study/record")
    public ResponseEntity<Void> addStudyRecord(@NotNull(message = "学习id不能为空") Integer studyId,
                                               @NotNull(message = "类型不能为空") Integer type,
                                               @NotBlank(message = "名称不能为空") String name,
                                               @NotNull(message = "医生id不能为空") Integer doctorId,
                                               BigDecimal rate,
                                               String img,
                                               Integer chapter) {
        doctorStudyRecordService.addStudyRecord(studyId, type, rate, name, img, chapter, doctorId);
        return ResponseEntity.ok().build();
    }

    /**
     * 分页查询我的学习
     */
    @GetMapping("/study/page")
    public ResponseEntity<Page<DoctorStudyRecord>> queryDoctorStudyPage(@Valid DoctorStudyReq req) {
        Page<DoctorStudyRecord> recordPage = doctorStudyRecordService.queryDoctorStudyPage(req);
        return ResponseEntity.ok(recordPage);
    }

    /**
     * 删除学习记录
     */
    @PostMapping("/update/study/status")
    public ResponseEntity<Void> updateStudyStatus(@NotBlank(message = "学习id不能为空") String studyIds) {
        doctorStudyRecordService.updateStudyStatus(studyIds);
        return ResponseEntity.ok().build();
    }

    /***
     * 获取广告弹框
     */
    @GetMapping("/doctor/advert/page")
    public ResponseEntity<Page<AdvertInfo>> queryDoctorAdvertPage(@Valid AdvertInfoReq req) {
        Page<AdvertInfo> page = iAdvertInfoService.queryDoctorAdvertPage(req);
        return ResponseEntity.ok(page);
    }


    /**
     * 查询开屏信息
     */
    @GetMapping("/doctor/post/info")
    public ResponseEntity<SpreadInfo> querySpreadInfo() {
        SpreadInfo spreadInfo = spreadInfoService.querySpreadInfo();
        return ResponseEntity.ok(spreadInfo);
    }

    /**
     * 获取私聊id
     */
    @PostMapping("/webSocket/group/id")
    public ResponseEntity<Integer> queryWebSocketGroupId() {
        Integer groupId = doctorUserService.queryWebSocketGroupId();
        return ResponseEntity.ok(groupId);
    }

    /**
     * 获取最新消息
     */
    @GetMapping("/webSocket/new/message")
    public ResponseEntity<Integer> queryNewMessage() {
        Integer num = webSocketImMsgService.queryNewMessage();
        return ResponseEntity.ok(num);
    }

    /**
     * 查询是否接受
     */
    @GetMapping("/webSocket/private/info")
    public ResponseEntity<WebSocketReq> queryIsAcceptWebSocket(@RequestParam("privateGroupId") Integer privateGroupId) {
        WebSocketReq res = webSocketImMsgService.queryIsAcceptWebSocket(privateGroupId);
        return ResponseEntity.ok(res);
    }

    /**
     * 获取最新消息
     */
    @GetMapping("/addDoctorOrderIncomeDetail")
    public ResponseEntity<Void> addDoctorOrderIncomeDetail() {
        doctorDetailService.sendDocDataToSupervise();
        return ResponseEntity.ok().build();
    }

    /**
     * 更新名称奖励
     */
    @PostMapping("/update/integtal")
    public ResponseEntity<Void> updateDoctorIntegtal(){
        doctorIntegralService.updateDoctorIntegtal();
        return ResponseEntity.ok().build();
    }
}

